//
//  ViewATMListController.m
//  bbqpitbooking
//
//  Created by Win Kyi Tin on 5/29/11.
//  Copyright 2011 iss. All rights reserved.
//

#import "ViewATMListController.h"
#import "Course.h"
#import "ATMDetailController.h"

#import "bbqpitbookingAppDelegate.h"
#import "BBQPit.h"
#import "BBQPitBooking.h"
#import "Customer.h"
#import "Park.h" 
#import "ParkArea.h"


@implementation ViewATMListController
@synthesize customer,bookingArray;


#pragma mark -
#pragma mark View lifecycle


-(void) viewDidLoad
{
	[super viewDidLoad];
	self.title = @"AXS Lists";
	courses = [[Course getExistingCourses] retain];
	
	
	locationManager = [[CLLocationManager alloc] init];
	locationManager.delegate = self;
	locationManager.distanceFilter = kCLDistanceFilterNone; 
	locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
	[locationManager startUpdatingLocation];
	
}



#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
    // Return the number of rows in the section.
    return [courses count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	

    
	static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
	//cell.font =[UIFont fontWithName:@"Helvetica" size:12.0];
	[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
	
	[[cell textLabel] setText:[[courses objectAtIndex:[indexPath row]] courseId]];
	[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    return cell;
}


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	// Check if I need to create the instance of CourseDetailController?
	if (!detailViewController) {
		detailViewController = [[ATMDetailController alloc] init];
	}
	
	// Give detail view controller a pointer to the course object in this row
	[detailViewController setEditingCourse: [courses objectAtIndex:[indexPath row]]];
	
	// Push it onto the top of the navigation controller's stack
	[[self navigationController] pushViewController:detailViewController 
										   animated:YES]; 
	
}



- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[detailViewController release];
	[courses release];
    [super dealloc];
}


- (void )didUpdateToLocation: (CLLocation *)newLocation
		  fromLocation:(CLLocation *)oldLocation
{	
	/*NSLog(@"%@", newLocation);
	noUpdates++;
	if(noUpdates >= 10){
		[locationManager stopUpdatingLocation];
		
	}
	
		NSLog(@"before updateLocation");
	[self updateLocation:[newLocation description]];
	 */
	
	
/*	int degrees = newLocation.coordinate.latitude;
	double decimal = fabs(newLocation.coordinate.latitude - degrees);
	int minutes = decimal * 60;
	double seconds = decimal * 3600 - minutes * 60;
	NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
					 degrees, minutes, seconds];
	NSLog(@"latitude %@",lat);
	degrees = newLocation.coordinate.longitude;
	decimal = fabs(newLocation.coordinate.longitude - degrees);
	minutes = decimal * 60;
	seconds = decimal * 3600 - minutes * 60;
	NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
					   degrees, minutes, seconds];
	NSLog(@"latitude %@",longt);*/
	
	
	
	double decimallatitude = newLocation.coordinate.latitude;
		NSLog(@"latitude %@",decimallatitude);
	
	double decimallongitude = newLocation.coordinate.longitude;
		NSLog(@"latitude %@",decimallongitude);
	
	
} 

/*
-(void) updateLocation:(NSString*) locationDesc{
	NSLog(@"hihi %@",locationDesc);

}*/

-(void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *) error
{
	NSLog(@"Could not locate location: %@", error);
}

/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
		locationManager = [[CLLocationManager alloc] init];
		[locationManager setDelegate:self];		
		[locationManager startUpdatingLocation];
	}
    return self;
} */


@end
